﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;

namespace GISCommon.UI
{
    public partial class IdentityCom : Component
    {
        public IdentityCom()
        {
            InitializeComponent();
            Initial();
        }

        public IdentityCom(IContainer container)
        {
            container.Add(this);

            InitializeComponent();

            Initial();
        }

        private IdentityForm frmIdentity;
        private AxMapControl m_pMapControl=null;
        //private bool IsExit

        public void Initial()
        {
            try
            {
                if (m_pMapControl == null)
                {
                    //System.Windows.Forms.MessageBox.Show("请先设置MapControl属性！");
                    return;
                }
                frmIdentity = new IdentityForm(m_pMapControl);
            }
            catch (Exception ex)
            {
                Console.WriteLine("调用IdentityCom.Initial()出错！" + ex.Message.ToString());
            }
        }

        public void Initial(AxMapControl vMapControl)
        {
            m_pMapControl = vMapControl;
            Initial();
        }

        public void Initial(IFeature vFeature, IFeatureLayer vFeatureLayer, AxMapControl vMapControl)
        {
            try
            {
                m_pMapControl = vMapControl;
                frmIdentity = new IdentityForm(vFeature, vFeatureLayer, vMapControl);
            }
            catch (Exception ex)
            {
                Console.WriteLine("调用IdentityCom.Initial()出错！" + ex.Message.ToString());
            }
        }

        public void Show()
        {
            try
            {
                //Initial();
                frmIdentity.BeforeShowForm();
                frmIdentity.Show();
                frmIdentity.TopMost = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("调用IdentityCom.Show()出错！" + ex.Message.ToString());
            }
        }

        /// <summary>
        /// 描述：地图控件

        /// </summary>
        public AxMapControl MapControl
        {
            get { return m_pMapControl; }
            set 
            { 
                m_pMapControl = value;
                //Initial();
            }
        }

    }
}
